const WindowsBot = require('WindowsBot');//引用WindowsBot模块

//注册主函数
WindowsBot.registerMain(windowsMain, "127.0.0.1", 26678);

/**用作代码提示，windowsMain函数会被多次调用，注意使用全局变量
* @param {WindowsBot} windowsBot
*/18


async function windowsMain(windowsBot){
    //设置隐式等待
    await windowsBot.setImplicitTimeout(1000);

    //查找第一个tim准备自动登录
    let tim1 = await windowsBot.findWindow(null, "TIM");
    console.log("tim1",tim1)

    if(tim1 ==  null)
    {
        console.log("tim1没有启动，我去启动一下")
        //启动程序
        await windowsBot.startProcess("D:\\Program Files (x86)\\Tencent\\TIM\\Bin\\QQScLauncher.exe", showWindow = true, isWait = false);
    }
    else
    {
        console.log("tim1启动，我要去操作一下编辑框")

        let position=await windowsBot.getWindowPos(tim1);
        console.log("tim1 位置",position)
    
        let topnow=await windowsBot.setWindowTop(tim1,true);
        console.log("是否置顶",topnow)
    
        await windowsBot.setWindowPos(tim1, 0, 0,725,584);
    
        await windowsBot.clickMouse(tim1, 600, 250 , 1, options = {});
        await windowsBot.sendVk(0x61, 1);
        await windowsBot.sendVk(0x68, 1);
        await windowsBot.sendVk(0x5C, 1);
    
        //点击登录
        await windowsBot.clickMouse(tim1, 658, 306 , 1, options = {});
    
         
        console.log("操作完毕")
    }

   
    
}